package com.greensecurity.sim.util;

import com.greensecurity.sim.entity.*;
import lombok.extern.slf4j.Slf4j;
import org.junit.Test;

import java.math.BigDecimal;
import java.math.RoundingMode;

@Slf4j
public class SplitUser {

    public static void splitUser(User user){
        String userPhotoUrl =  user.getUserPhotoUrl();
        userPhotoUrl = userPhotoUrl.split(IsWindowOrLinuxUtils.getPhotoUrl())[1];
        for (GreenLand greenLand : user.getGreenLands()){
            for (GreenLandPhoto greenLandPhoto : greenLand.getGreenLandPhotos()){
                greenLandPhoto.setPhotoUrl(greenLandPhoto.getPhotoUrl().split(IsWindowOrLinuxUtils.getPhotoUrl())[1]);
            }
        }
        user.setUserPhotoUrl(userPhotoUrl);
    }

    //新方法
    public static void newSplitUser(User user){
        String userPhotoUrl =  user.getUserPhotoUrl();
        //消除用户头像的地址前缀
        userPhotoUrl = userPhotoUrl.split(IsWindowOrLinuxUtils.getPhotoUrl())[1];
        //消除每张绿地照片的地址前缀
        for (Green green : user.getGreen()){
            for (GreenLandPhoto greenLandPhoto : green.getGreenLandPhotos()){
                greenLandPhoto.setPhotoUrl(greenLandPhoto.getPhotoUrl().split(IsWindowOrLinuxUtils.getPhotoUrl())[1]);
                log.info("绿地图片地址（新）"+greenLandPhoto.getPhotoUrl());
            }
        }
//        for (GreenLand green : user.getGreenLands()){
//            for (GreenLandPhoto greenLandPhoto : green.getGreenLandPhotos()){
//                greenLandPhoto.setPhotoUrl(greenLandPhoto.getPhotoUrl().split(IsWindowOrLinuxUtils.getPhotoUrl())[1]);
//                log.info("绿地图片地址"+greenLandPhoto.getPhotoUrl());
//            }
//        }
        user.setUserPhotoUrl(userPhotoUrl);
    }

}
